import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsOptional, IsArray, ValidateNested, IsEnum } from 'class-validator';
import { Type } from 'class-transformer';

// AI message DTO
export class AIMessageDto {
  @ApiProperty({ description: 'Message role', enum: ['system', 'user', 'assistant'] })
  @IsEnum(['system', 'user', 'assistant'])
  role: 'system' | 'user' | 'assistant';

  @ApiProperty({ description: 'Message content' })
  @IsString()
  content: string;
}

// Generate response request DTO
export class GenerateResponseDto {
  @ApiProperty({ description: 'Message history', type: [AIMessageDto] })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => AIMessageDto)
  messages: AIMessageDto[];

  @ApiProperty({ description: 'Persona prompt' })
  @IsString()
  personaPrompt: string;

  @ApiProperty({ description: 'AI model', required: false, default: 'gpt-4o-mini' })
  @IsOptional()
  @IsString()
  model?: string;
}

// Text-to-speech request DTO
export class TTSRequestDto {
  @ApiProperty({ description: 'Text to convert' })
  @IsString()
  text: string;

  @ApiProperty({ description: 'Voice', required: false, default: '21m00Tcm4TlvDq8ikWAM' })
  @IsOptional()
  @IsString()
  voice?: string;

  @ApiProperty({ description: 'Audio format', required: false, default: 'mp3' })
  @IsOptional()
  @IsString()
  format?: string;

  @ApiProperty({ description: 'Language', required: false, default: 'en', enum: ['en', 'zh'] })
  @IsOptional()
  @IsEnum(['en', 'zh'])
  language?: string;
}

// Speech-to-text request DTO
export class ASRRequestDto {
  @ApiProperty({ description: 'Audio data (base64)' })
  @IsString()
  audioData: string;

  @ApiProperty({ description: 'Language', required: false, default: 'en' })
  @IsOptional()
  @IsString()
  language?: string;

  @ApiProperty({ description: 'Audio mime type', required: false, example: 'audio/wav' })
  @IsOptional()
  @IsString()
  mimeType?: string;
}
